package com.lry.filter.client;

import com.lry.filter.server.ServerFilter;
import com.lry.protocol.RpcInvocation;
import com.lry.protocol.RpcMessage;
import com.lry.rpc.netty.RpcContext;
import com.lry.spi.LoadLevel;
import com.lry.util.CollectionUtils;

import java.util.Map;

@LoadLevel(name = "rpcContext")
public class ClientRpcContextFilter implements ClientFilter {
    @Override
    public void filter(RpcMessage rpcMessage) {
        if(rpcMessage.getBody() instanceof RpcInvocation){
            RpcInvocation rpcInvocation = (RpcInvocation) rpcMessage.getBody();
            if(CollectionUtils.isNotEmpty(RpcContext.getContext())){
                rpcInvocation.addHeads(RpcContext.getContext());
            }
        }
    }
}
